package com.itstudy.controller;

import com.itstudy.pojo.Result;
import com.itstudy.utils.AliOssUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
public class UploadController {

    @PostMapping("upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        //把文件内容存到本地磁盘
        String originalFilename = file.getOriginalFilename();
        //保证文件名唯一防止覆盖
        String s = UUID.randomUUID().toString() + "_" + originalFilename;

        String url = AliOssUtil.uploadFile(s, file.getInputStream());
        return Result.success(url);
    }
}
